package cc.rengu.redp.bizimpl.igas.service.impl;

import cc.rengu.redp.bizimpl.constant.UpmpConstant;
import cc.rengu.redp.bizimpl.igas.bean.PayChannelNetInfo;
import cc.rengu.redp.bizimpl.igas.dao.PayChannelNetMapper;
import cc.rengu.redp.bizimpl.igas.service.PayChannelNetService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.utils.SortUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("payChannelNetService")
@Slf4j
@DS("igas")
public class PayChannelNetServiceImpl extends ServiceImpl<PayChannelNetMapper,PayChannelNetInfo> implements PayChannelNetService {
    @Autowired
    private IUpmpSysParamService upmpSysParamService;
    @Override
    public IPage<PayChannelNetInfo> findByKey(QueryRequest request, PayChannelNetInfo info) {
        try {
            String instId = upmpSysParamService.getById(UpmpConstant.IGAS_DEFAULT_INST_ID).getPrimaryValue();
            String paramType = "aliPay";
            String paramKey = "aliPaySwitchFlag";
            LambdaQueryWrapper<PayChannelNetInfo> queryWrapper = new LambdaQueryWrapper<>();
            if(instId !=null){
                queryWrapper.eq(PayChannelNetInfo::getInstId,instId);
            }
            if(paramType !=null){
                queryWrapper.eq(PayChannelNetInfo::getParamType,paramType);
            }
            if(paramKey !=null){
                queryWrapper.eq(PayChannelNetInfo::getParamKey,paramKey);
            }
            Page<PayChannelNetInfo> page = new Page<>();
            SortUtil.handlePageSort(request, page, true);

            return this.page(page,queryWrapper);
        } catch (Exception e) {
            log.error("获取信息失败", e);
            return null;
        }
    }
}
